﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;


namespace DemoAstarAlgorithm {
    class cTime {
        SpriteFont m_sfFontTime;

        public int m_iMinute;
        public int m_iSecond;
        int m_iCount;
        public cTime(ContentManager content) {
            m_iMinute = 3;
            m_iSecond = 0;
            m_iCount = 0;
            m_sfFontTime = content.Load<SpriteFont>(@"fonts/ComicSansMS");
        }

        public void Draw(SpriteBatch spriteBatch, GameTime gameTime, ManagerMap managerMap) {
            if (m_iMinute == 0 && m_iSecond == 0 && Game1.g_bPause == false) {
                Game1.g_bPause = true;
                managerMap.m_iTimeStatus = 0;
                managerMap.m_iIDStatus = 3;
            }
            if (Game1.g_bPause == false) {
                m_iCount += gameTime.ElapsedGameTime.Milliseconds;
                if (m_iCount > 1000) {
                    m_iSecond--;
                    m_iCount = 0;
                    if (m_iSecond % 5 == 0) Game1.g_iEnergy++;
                }
                if (m_iSecond < 0) {
                    m_iMinute--;
                    m_iSecond = 59;
                }

            }
            if ((managerMap.m_iIDStatus == 4) && (m_iSecond > 0 || m_iMinute > 0)) {
                m_iCount += gameTime.ElapsedGameTime.Milliseconds;
                if (m_iCount > 10) {
                    m_iSecond--;
                    m_iCount = 0;
                }
                if (m_iSecond < 0) {
                    m_iMinute--;
                    m_iSecond = 59;
                }
                Game1.g_iScore++;
            }
            if (m_iSecond >= 10)
                spriteBatch.DrawString(m_sfFontTime, m_iSecond.ToString(),
                    new Vector2(720, 105), Color.Yellow, 0, Vector2.Zero, 1, SpriteEffects.None, 1);
            else {
                spriteBatch.DrawString(m_sfFontTime, "0",
                    new Vector2(720, 105), Color.Yellow, 0, Vector2.Zero, 1, SpriteEffects.None, 1);
                spriteBatch.DrawString(m_sfFontTime, m_iSecond.ToString(),
                    new Vector2(740, 105), Color.Yellow, 0, Vector2.Zero, 1, SpriteEffects.None, 1);
            }
            spriteBatch.DrawString(m_sfFontTime, m_iMinute.ToString() + " : ",
                new Vector2(680, 105), Color.Yellow, 0, Vector2.Zero, 1, SpriteEffects.None, 1);
            spriteBatch.DrawString(m_sfFontTime, " Timer ",
                new Vector2(665, 75), Color.Yellow, 0, Vector2.Zero, 1, SpriteEffects.None, 1);
            spriteBatch.DrawString(m_sfFontTime, " Score ",
               new Vector2(665, 136), Color.Yellow, 0, Vector2.Zero, 1, SpriteEffects.None, 1);
        }
    }
}